package org.huawei260.TiKu.ODsuanfa;

import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class A_2023A_2701__哈希集合寻找关键钥匙 { // 65%通过

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			String password = sc.next().toLowerCase();
			String[] boxes = sc.nextLine().split(" ");

			for (int i = 0; i < boxes.length; i++) {
				String box = boxes[i];
				Set<Character> letters = extractAndSortLetters(box);
				if (letters.containsAll(password.chars().mapToObj(c -> (char) c).collect(java.util.stream.Collectors.toList())) && letters.size() == password.length()) {
					System.out.println(i + 1);
					return;
				}
			}
			System.out.println(-1);
		}

		private static Set<Character> extractAndSortLetters(String box) {
			Set<Character> letters = new TreeSet<>();
			for (char c : box.toCharArray()) {
				if (Character.isLetter(c)) {
					letters.add(Character.toLowerCase(c));
				}
			}
			return letters;
		}
	}